﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.Business;

namespace BLL.Controler
{
    public class KQTongHopTheoNamCuaTungMonCtlr
    {
        public static IList<KQTongHopTheoNamCuaTungMonInfo> LayDsKQHocKyTongHop(String maLop,String idMon, String maNamHoc)
        {
            IList<KQTongHopTheoNamCuaTungMonInfo> dS = new List<KQTongHopTheoNamCuaTungMonInfo>();
            BangDiemBUO bdBUO = new BangDiemBUO();
            String idLop = maLop;
            String idHocSinh;
            double diemk1 = 0;
            double diemk2 = 0;
            double diemTK = 0;
            int dem1 = 0, dem2 = 0;
            foreach (String item in bdBUO.getAllIdHocSinhByIdLop(idLop))
            {
                idHocSinh = item;
                //Tổng kết môn kỳ 1
                try
                {
                    foreach (String item1 in bdBUO.showBangDiemTheoLopTheoTungMon_K1(maNamHoc,idMon,idLop))
                    {
                        diemk1 += double.Parse(item1);
                        dem1++;
                        diemk1 = (double)(diemk1 * 1.0 / dem1);
                    }
                }
                catch (Exception)
                {
                }
                //Tổng kết môn kỳ 2
                try
                {
                    foreach (String item2 in bdBUO.showBangDiemTheoHocSinhCuaTatCaMonTrongNam_K2(maNamHoc, idHocSinh))
                    {
                        diemk2 += double.Parse(item2);
                        dem2++;
                        diemk2 = (double)(diemk2 * 1.0 / dem2);
                    }
                }
                catch (Exception)
                {
                }
                diemTK = (double)((diemk1 + diemk2 * 2) / 3.0);
                KQTongHopTheoNamCuaTungMonInfo ketqua = new KQTongHopTheoNamCuaTungMonInfo();
                ketqua.DiemTongKet = diemTK;
                ketqua.id_HocSinh = bdBUO.getHS(idHocSinh).id_HocSinh.ToString();
                ketqua.HoTenHS = bdBUO.getHS(idHocSinh).HoTenHS.ToString();
                ketqua.NgaySinh = bdBUO.getHS(idHocSinh).NgaySinh.ToString();

                dS.Add(ketqua);
                diemk1 = 0; dem1 = 0;
                diemk2 = 0; dem2 = 0;
            }


            //foreach (DataRow Row in m_DT.Rows)
            //{
            //    KQHocKyTongHopInfo ketqua = new KQHocKyTongHopInfo();

            //    HocSinhInfo hs = new HocSinhInfo();
            //    hs.MaHocSinh = Convert.ToString(Row["MaHocSinh"]);
            //    hs.HoTen = Convert.ToString(Row["HoTen"]);

            //    LopInfo l = new LopInfo();
            //    l.MaLop = Convert.ToString(Row["MaLop"]);
            //    l.TenLop = Convert.ToString(Row["TenLop"]);

            //    HocKyInfo hk = new HocKyInfo();
            //    hk.MaHocKy = Convert.ToString(Row["MaHocKy"]);
            //    hk.TenHocKy = Convert.ToString(Row["TenHocKy"]);

            //    NamHocInfo nh = new NamHocInfo();
            //    nh.MaNamHoc = Convert.ToString(Row["MaNamHoc"]);
            //    nh.TenNamHoc = Convert.ToString(Row["TenNamHoc"]);

            //    HocLucInfo hl = new HocLucInfo();
            //    hl.MaHocLuc = Convert.ToString(Row["MaHocLuc"]);
            //    hl.TenHocLuc = Convert.ToString(Row["TenHocLuc"]);

            //    HanhKiemInfo hkiem = new HanhKiemInfo();
            //    hkiem.MaHanhKiem = Convert.ToString(Row["MaHanhKiem"]);
            //    hkiem.TenHanhKiem = Convert.ToString(Row["TenHanhKiem"]);

            //    ketqua.HocSinh = hs;
            //    ketqua.Lop = l;
            //    ketqua.HocKy = hk;
            //    ketqua.NamHoc = nh;
            //    ketqua.HocLuc = hl;
            //    ketqua.HanhKiem = hkiem;
            //    ketqua.DTBMonHocKy = Convert.ToSingle(Row["DTBMonHocKy"]);

            //    dS.Add(ketqua);
            //}
            return dS;

        }
    }
}
